﻿#include "uimodelsigbaseedit.h"

#include <ElaProgressBar.h>
#include <ElaComboBox.h>
#include <ElaLineEdit.h>
#include <ElaIconButton.h>
#include <ElaContentDialog.h>
#include <ElaText.h>
#include <ElaTabWidget.h>
#include <ElaSpinBox.h>

#include <QGroupBox>

#include <QHBoxLayout>

UiModelSigBaseEdit::UiModelSigBaseEdit(QSharedPointer<CRtModelSigBase> sig, QStringList groups,EOptmode mode, QWidget *parent)
    : QWidget{parent}, m_editptr(sig)
{
    bool enedit = false;
    if(ECreate == mode) {
        enedit == true;
    } else {
        enedit = false;
    }

    this->setWindowFlags(Qt::WindowType::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground, true);
    QVBoxLayout* vlayout = new QVBoxLayout;
    vlayout->setSpacing(20);

    int fontSize = 16;
    int lineHeidht = 32;

    ElaText* lab_tmp_user = new ElaText("所属用户:", this);
    lab_tmp_user->setMinimumHeight(lineHeidht);
    lab_tmp_user->setTextPointSize(fontSize);
    ElaText* lab_user = new ElaText(sig->user, this);
    lab_user->setTextPointSize(fontSize);
    QHBoxLayout* layout = new QHBoxLayout;
    layout->addWidget(lab_tmp_user, 1);
    layout->addWidget(lab_user, 3);
    vlayout->addLayout(layout);

    ElaText* lab_tmp_model = new ElaText("所属模型:", this);
    lab_tmp_model->setTextPointSize(fontSize);
    ElaText* lab_model = new ElaText(sig->model_name, this);
    lab_model->setTextPointSize(fontSize);
    layout = new QHBoxLayout;
    layout->addWidget(lab_tmp_model, 1);
    layout->addWidget(lab_model, 3);
    vlayout->addLayout(layout);

    ElaText* lab_tmp_su = new ElaText("信号序号:", this);
    lab_tmp_su->setTextPointSize(fontSize);
    ElaText* lab_sn = new ElaText(QString::number(sig->sn) ,this);
    lab_sn->setTextPointSize(fontSize);
    layout = new QHBoxLayout;
    layout->addWidget(lab_tmp_su, 1);
    layout->addWidget(lab_sn, 3);
    vlayout->addLayout(layout);

    ElaText* lab_tmp_name = new ElaText("信号名字:", this);
    lab_tmp_name->setTextPointSize(fontSize);
    m_let_name = new ElaLineEdit(this);
    m_let_name->setReadOnly(enedit);
    QFont font = m_let_name->font();
    font.setPointSize(15);
    m_let_name->setFont(font);
    m_let_name->setMinimumHeight(lineHeidht);
    m_let_name->setText(sig->name);
    layout = new QHBoxLayout;
    layout->addWidget(lab_tmp_name, 1);
    layout->addWidget(m_let_name, 3);
    vlayout->addLayout(layout);

    ElaText* lab_tmp_descr = new ElaText("信号描述:", this);
    lab_tmp_descr->setTextPointSize(fontSize);
    m_let_descr = new ElaLineEdit(this);
    m_let_descr->setFont(font);
    m_let_descr->setMinimumHeight(lineHeidht);
    m_let_descr->setText(sig->descr);
    layout = new QHBoxLayout;
    layout->addWidget(lab_tmp_descr, 1);
    layout->addWidget(m_let_descr, 3);
    vlayout->addLayout(layout);

    ElaText* lab_tmp_group = new ElaText("信号分组:", this);
    lab_tmp_group->setTextPointSize(fontSize);
    m_cbx_group = new ElaComboBox(this);
    m_cbx_group->addItems(groups);
    m_cbx_group->setEditable(true);
    if(!sig->grouping.isEmpty() && groups.contains(sig->grouping))
        m_cbx_group->setCurrentText(sig->grouping);
    layout = new QHBoxLayout;
    layout->addWidget(lab_tmp_group, 1);
    layout->addWidget(m_cbx_group, 3);
    vlayout->addLayout(layout);
    vlayout->addStretch(1);

    QGroupBox* baseeditw = new QGroupBox(this);
    baseeditw->setTitle("基础属性编辑");
    baseeditw->setLayout(vlayout);

    QVBoxLayout* mainLayout = new QVBoxLayout;
    mainLayout->addWidget(baseeditw);
    this->setLayout(mainLayout);
}

void UiModelSigBaseEdit::save()
{
    m_editptr->name = m_let_name->text();
    m_editptr->descr = m_let_descr->text();
    m_editptr->grouping = m_cbx_group->currentText();
}
